﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using MockPrjTeam4.Entity;
using MockPrjTeam4.Biz;
using MockPrjTeam4.Common;
 

namespace MockPrjTeam4
{
    public partial class ContactAdd : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string popup = @"<script>
            function popup(url, width, height)
            {
                //var width = 500;
                //var height = 400;
                var left = (screen.width - width) / 2;
                var top = (screen.height - height) / 2;
                var params = 'width=' + width + ', height=' + height;
                params += ', top=' + top + ', left=' + left;
                params += ', directories=no';
                params += ', location=no';
                params += ', menubar=no';
                params += ', resizable=no';
                params += ', scrollbars=yes';
                params += ', status=no';
                params += ', toolbar=no';
                newwin = window.open(url, 'windowname5', params);
                if (window.focus) 
                { 
                    newwin.focus() 
                }
                return false;
            }
            </script>";
            if (!Page.ClientScript.IsStartupScriptRegistered("Mast"))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(),
                    "Mast", popup);
            }

            string scripthtml = @"<script>
            function validateTxt(){ 
                    
                      html = $(this).val(); //get the value
                      //.replace('a' , 'b')  works only on first occurrence of 'a'
                      html = html.replace(/< /g, '<'); //before: if there's space after < remove
                      html = html.replace(/</g, '< '); // add space after <
                      $(this).val(html); //set new value
                }
            </script>";
            if (!Page.ClientScript.IsStartupScriptRegistered("MastHTM"))
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(),
                    "MastHTM", scripthtml);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Contacts contact = new Contacts();
            contact.FirstName = txtFirstName.Text;
            contact.SurName = txtSurname.Text;
            contact.Alias = txtKnownAs.Text;
            contact.OfficePhone = txtOfficePhone.Text;
            contact.MobilePhone = txtMobilePhone.Text;
            contact.HomePhone = txtHomePhone.Text;
            contact.Email = txtEmail.Text;
            contact.ManagerID = Methods.ConvertNumber(hdfContact.Value);
            contact.ContactType = ddlContactType.SelectedItem.Value;
            contact.BestContactMethod = ddlBestContactMethod.Text;
            contact.JobRole = txtJobRole.Text;
            contact.WorkBase = txtWorkbase.Text;
            contact.JobTitle = txtJobTitle.Text;
            if (chkIsActive.Checked) contact.IsActive = true;
            else contact.IsActive = false;
            ContactBiz.AddContact(contact);
            lblMessage.Text = "You added " + txtFirstName.Text + " "+ txtSurname.Text + " successfully";
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("../Views/ListContact.aspx");
        }

        protected void txtFirstName_TextChanged(object sender, EventArgs e)
        {

        }
    }
}